package gui;

import processing.core.PApplet;

public class MultistateButton extends Widget {
	PolyButton[] states;
	int lastDefined = -1;
	int current = 0;
	boolean hidden = false;
	  
	public MultistateButton(PApplet parent_applet, int N, float[] pos) {
		super(parent_applet, pos);
		states = new PolyButton[N];
	}
	
	/*
	public MultistatePolyButton(PApplet parent_applet, int N, PolyButton firstState) {
		super(parent_applet, firstState);
		states = new PolyButton[N];
		addState(firstState);
	}
	*/

	private int addState(PolyButton btn) {
		if (lastDefined < states.length) {
			lastDefined++;
			states[lastDefined] = btn;
			states[lastDefined].hidden = true;
			if (lastDefined == current) {
				syncPosition();
			}
			return lastDefined;
		} else {
			return -1;
		}
	}
	  
	PolyButton currentState() {
		return states[current];
	}
	
	void syncPosition() {
		PolyButton s = currentState();
		x0 = s.x0;
		y0 = s.y0;
		width = s.width;
		height = s.height;
	}
	
/*
	private boolean update() {
		boolean result = false;
		if (!hidden) {
			states[current].hidden = false;
			result = states[current].update();
			if (result) {
				states[current].hidden = true;
				current++;
				if (current==states.length) {current=0;}
				syncPosition();
			}
		}
		return result;
	}
*/
	public void draw() {
		if (!hidden) {
			states[current].draw();
		}
	}
	  
}


